
/**
 * 
 * the grammar of ShaderLib :)
 * 
 * shaderlib := 'Shader' NAME '{' shader_body '}'
 * 
 * shader_body := tag_groups? pass_def+
 * 
 * tag_groups := 'Tags' '{' tag_pair [',' tag_pair]* '}'
 * tag_pair := STRING '=' STRING
 * 
 * pass_def := 'Pass' '{' pass_body '}'
 * pass_body := ['Name' STRING] pass_meta_decl* wgsl_body
 * 
 * pass_meta_decl := 
 *  | cull_decl
 *  | zWrite_decl
 *  | blend_decl
 *  | blend_op_decl
 * 
 * cull_decl := 'Cull' STRING
 * zWrite_del := 'ZWrite' STRING
 * blend_decl := 'Blend' STRING STRING
 * blend_op_decl := 'BlendOp' STRING
 * 
 * wgsl_body := 'WGSLPROGRAM' [TOKEN except 'WGSLEND']* 'WGSLEND' 
 */

import { WgslReflect } from "wgsl_reflect"

const _ = 0


export const gpuCullModeArray = ['none', 'front', 'back']
export const gpuBlendOp = [
    'add', 'subtract', 'reverse-subtract',
    'min', 'max'
]
export const gpuBlendFactor = [
    "zero", 
    "one", 
    "src", 
    "one-minus-src", 
    "src-alpha", 
    "one-minus-src-alpha", 
    "dst", 
    "one-minus-dst", 
    "dst-alpha", 
    "one-minus-dst-alpha", 
    "src-alpha-saturated", 
    "constant", 
    "one-minus-constant", 
    "src1", 
    "one-minus-src1", 
    "src1-alpha", 
    "one-minus-src1-alpha"
]


export interface NodeShaderLib {
    shaderName: string
    shaderBody: NodeShaderBody
}

export interface NodeShaderBody {
    tags: Record<string, string>
    passes: Array<NodePassBody>
}

export interface NodePassBody {
    passName: string
    cullMode: GPUCullMode
    zWrite: boolean

    enableBlend: boolean
    blendSrcFactor: GPUBlendFactor
    blendDstFactor: GPUBlendFactor
    blendOp: GPUBlendOperation

    wgslProgram: string
    wgslReflect: WgslReflect
}
